import java.awt.Graphics;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Random;

import javax.swing.JOptionPane;

import edu.uwm.cs552.HexBoard;
import edu.uwm.cs552.HexBoardPanel;
import edu.uwm.cs552.HexCoordinate;
import edu.uwm.cs552.gfx.AnimationApplet;


public class TestHexBoardPanel extends AnimationApplet {

	/**
	 * Keep Eclipse Happy
	 */
	private static final long serialVersionUID = 1L;
	
	double scale = 10.0;
	Random r = new Random();
	HexBoardPanel panel;
	
	@Override 
	public void initialize() {
		String hbs = getParameter("board");
		HexBoard board = new HexBoard(null,50,25);
		if(hbs != null) {
			try {
				board = HexBoard.read(new BufferedReader(new FileReader(hbs)));
			} catch (Exception e) {
				JOptionPane.showMessageDialog(this, e.getMessage(), "Error reading board", JOptionPane.ERROR_MESSAGE);
			}
		}
		panel = new HexBoardPanel(board);
		add(panel);
	}
	
	@Override
	public void move() {
		panel.setScale(scale *= 1.025);
		if (scale > 40) panel.setDrawMesh(true);
	}

	@Override
	public void paint(Graphics g) {
		super.paint(g);
		panel.toggleSelection(new HexCoordinate(r.nextInt(20),r.nextInt(10)));
	}
}
